home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / PageMaker 6.5 SDK Mac / SourceCode / PageMakerClassLibrary / LowLevel / PRequestBuf.cpp < prev    next >
C/C++ Source or Header  |  1996-09-05  |  3KB  |  149 lines

  1. /*
  2.  *--- PRequestBuf.cpp -----------------------------------------------------
  3.  * Copyright (c) 1995-96 Adobe Systems Incorporated.  All rights reserved.
  4.  * Created on Thu, Oct 19, 1995 @ 8:17 PM by Paul Ferguson.
  5.  *
  6.  * Description:  For notes about this class, refer to the
  7.  * header file PRequestBuf.h
  8.  *------------------------------------------------------------------------
  9.  */
  10.  
  11. //#include "PageMakerMemory.h"
  12. #include "PMCQErrs.h"
  13. #include "CIBasic.h"
  14. #include "CIInterfaceManager.h"
  15. #include "PMInterfaceIDs.h"
  16.  
  17. extern PMMessage * gPMMessage;
  18.  
  19. #include "PRequestBuf.h"
  20.  
  21. PRequestBuf::PRequestBuf(size_t bufSize) throw (PMErr)
  22. : bufHdl(0)
  23. {
  24.     CIBasic * basicInterface;
  25.     gPMMessage->pInterfaceMgr->AcquirePMInterface((unsigned long)PMIID_BASIC, (void **) &basicInterface);
  26.     bufPtr = (char *) basicInterface->PMMemAlloc(bufSize);
  27.     gPMMessage->pInterfaceMgr->ReleasePMInterface(basicInterface);
  28.  
  29.     if (bufPtr == NULL)
  30.         throw CQ_FAILURE;
  31.  
  32.  
  33.     curCh = bufPtr;
  34. }
  35.  
  36. PRequestBuf::PRequestBuf(void * h)
  37. : bufHdl(0), bufPtr((char *) h)
  38. {
  39.     curCh = bufPtr;
  40. }
  41.  
  42. PRequestBuf::~PRequestBuf()
  43. {
  44.     if (bufPtr)
  45.     {
  46.         CIBasic * basicInterface;
  47.         gPMMessage->pInterfaceMgr->AcquirePMInterface((unsigned long)PMIID_BASIC, (void **) &basicInterface);
  48.         basicInterface->PMMemFree(bufPtr);
  49.         gPMMessage->pInterfaceMgr->ReleasePMInterface(basicInterface);
  50.     }
  51. }
  52.  
  53. PRequestBuf& PRequestBuf::operator<< (short aShort)
  54. {
  55.     *((short *) curCh) = aShort;
  56.  
  57.     curCh += 2;
  58.     
  59.     return *this;
  60. }
  61.  
  62. PRequestBuf& PRequestBuf::operator<< (unsigned short aShort)
  63. {
  64.     *(unsigned short *) curCh = aShort;
  65.     curCh += 2;
  66.  
  67.     return *this;
  68. }
  69.  
  70. PRequestBuf& PRequestBuf::operator<< (long aLong)
  71. {
  72.     *(long *) curCh = aLong;
  73.     curCh += 4;
  74.     
  75.     return *this;
  76. }
  77.  
  78. PRequestBuf& PRequestBuf::operator<< (unsigned long aLong)
  79. {
  80.     *(unsigned long *) curCh = aLong;
  81.     curCh += 4;
  82.  
  83.     return *this;
  84. }
  85.  
  86. PRequestBuf& PRequestBuf::operator<< (const char * aString)
  87. {
  88.     if (aString)
  89.     {
  90.         register char * dest = curCh;
  91.         register const char * src = aString;
  92.         while (*dest++ = *src++)        // copy string, and null terminator
  93.             ;
  94.     
  95.         if (long(dest) & 0x01) ++dest;    // make sure have even alignment
  96.         curCh = dest;
  97.     }
  98.     else
  99.     {
  100.         *curCh++ = '\0';
  101.         *curCh++ = '\0';
  102.     }
  103.  
  104.     return *this;
  105. }
  106.  
  107. PRequestBuf& PRequestBuf::operator<< (const unsigned char * aString)        // A Pascal string
  108. {
  109.     if (aString)
  110.     {
  111.         register unsigned char * dest = (unsigned char *) curCh;
  112.         register const unsigned char * src = aString;
  113.         register size_t strLen = *src++;                            // Get length byte
  114.     
  115.         while ( (strLen--) && (*dest++ = *src++) )
  116.             ;                            // copy string, and null terminator
  117.     
  118.         *dest++ = '\0';
  119.     
  120.         if (long(dest) & 0x01) ++dest;    // make sure have even alignment
  121.         curCh = (char *) dest;
  122.     }
  123.     else
  124.     {
  125.         *curCh++ = '\0';
  126.         *curCh++ = '\0';
  127.     }
  128.  
  129.     return *this;
  130. }
  131.  
  132. PRequestBuf& PRequestBuf::operator<< (PRequestBuf& aBuf)
  133. {
  134.     if (&aBuf == this) return *this;    // don't copy onto self.
  135.  
  136.     register size_t size = aBuf.Size();
  137.     register const char * src = aBuf;    // start of its buffer
  138.     register char * dest = curCh;
  139.     
  140.     while (size--)
  141.         *dest++ = *src++;
  142.     
  143.     curCh += aBuf.Size();
  144.     
  145.     return *this;
  146. }
  147.  
  148. // end of PRequestBuf.cpp
  149.